// components/activity/activity-item/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS, ACTIVITY_TYPE, ACTIVITY_TYPE_MAP } from'../../../constants/common';
import { PACKAGE_ACTIVITY_PAGE, PACKAGE_MARKET_PAGE } from '../../../constants/route';
import { ACTIVITY_OWNER_VALUE, ACTIVITY_STATUS_VALUE, ACTIVITY_STATUS } from '../../../constants/activity';
import { getPicFullPath } from '../../../common/utils';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        type: {
            type: String,
            value: 'normal', // normal || advocacy || copy
        },
        activityInfo: {
            type: Object,
            value: {},
        },
        isHaveMore: {
            type: Boolean,
            value: true,
        },
    },
    observers: {
        'activityInfo': function (val) {
            if (val) {
                let detailPath = PACKAGE_ACTIVITY_PAGE['detail'];
                if (val.type === ACTIVITY_TYPE.lottery) {
                    detailPath = PACKAGE_MARKET_PAGE['lotteryDetail'];
                }
                this.setData({
                    avatarUrl: getPicFullPath(val.ownerPic),
                    statusStr: ACTIVITY_STATUS[val.processStatus],
                    detailPath,
                });
            }
        },
    },
    data: {
        ACTIVITY_TYPE_MAP,
        ACTIVITY_OWNER_VALUE,
        ACTIVITY_STATUS_VALUE,
        avatarUrl: '',
        statusStr: '',
        detailPath: '',
    },
    methods: {
        handleClick() {
            this.triggerEvent('click', this.data.activityInfo);
        },
        handleShare() {
            this.triggerEvent('share', this.data.activityInfo);
        },
        handleMore() {
            this.triggerEvent('more', this.data.activityInfo);
        },
        handleAdvocacy() {
            this.triggerEvent('advocacy', this.data.activityInfo);
        },
        handleCheckAdvocacy() {
            this.triggerEvent('check', this.data.activityInfo);
        },
        handleCopy() {
            this.triggerEvent('copy', this.data.activityInfo);
        },
    }
})
